package com.hua.designpattern.behavioral.interpreter;

public class NonterminalExpressionDivision implements NonterminalExpression {

	private InterpreterInterface leftExpression;

	private InterpreterInterface rightExpression;

	public NonterminalExpressionDivision(InterpreterInterface leftExpression, InterpreterInterface rightExpression) {
		super();
		this.leftExpression = leftExpression;
		this.rightExpression = rightExpression;
	}

	@Override
	public double interpreter(String context) {
		if (rightExpression.interpreter(context) == 0) {
			throw new ArithmeticException("Devision can not by zero(/0)");
		}
		return leftExpression.interpreter(context) / rightExpression.interpreter(context);
	}

}
